﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

/// <summary>
///HelpNava 的摘要说明
/// </summary>
public partial class HelpNava
{
    public static HelpNava Get(int id)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.HelpNava.FirstOrDefault(row => row.ID == id);
        }
    }
    public static HelpNava GetByTitle(string Title)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.HelpNava.FirstOrDefault(row => row.Title == Title);
        }
    }

    public static List<HelpNava> GetAll()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.HelpNava.OrderByDescending(row => row.Rank).ToList();
        }
    }

    public void Add()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            context.HelpNava.InsertOnSubmit(this);
            context.SubmitChanges();
        }
    }

    public void Update()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            this.GetType().GetMethod("Detach").Invoke(this, null);
            var tbl = context.GetTable<HelpNava>();
            tbl.Attach(this);
            context.Refresh(RefreshMode.KeepCurrentValues, this);
            context.SubmitChanges();
        }
    }

    public static void Delete(int id)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            var objItem = context.HelpNava.FirstOrDefault(row => row.ID == id);
            if (objItem == null)
                return;
            context.HelpNava.DeleteOnSubmit(objItem);
            context.SubmitChanges();
        }
    }

    public class AA
    {

        public int AA1 { get; set; }
        public int AA2 { get; set; }
        public string AA3 { get; set; }
    }

    public List<AA> GetAllAA()
    {
        using (DataClassesDataContext db = new DataClassesDataContext())
        {
            var query = from Hn in db.HelpNava
                        join hD in db.HelpDes
                        on Hn.ID equals hD.NavaID
                        select new AA
                        {
                            AA1 = Hn.ID,
                            AA2 = hD.NavaID,
                            AA3 = hD.Title
                        };
            return query.ToList();
        }
    }
}